package com.yueban.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yueban.R;
import com.yueban.constant.HttpConstant;
import com.yueban.model.User;
import com.yueban.views.CircleSmartImageView;

import java.util.List;

/**
 * Created by guan on 17-8-15.
 */

public class JoinListAdaper extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<User> users;
    private Context context;

    public JoinListAdaper(List<User> users) {
        this.users = users;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        this.context = parent.getContext();
        LayoutInflater inflater = LayoutInflater.from(context);
        return new JoinListAdaper.CardViewHolder(inflater.inflate(R.layout.item_join_content, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CardViewHolder cardViewHolder = (CardViewHolder) holder;
        User user = users.get(position);
        cardViewHolder.userName.setText(user.getName());
        cardViewHolder.imageView.setImageUrl(HttpConstant.SERVER_URL + HttpConstant.GET_USER_ICON
                + "?userId=" + user.getId());
    }

    @Override
    public int getItemCount() {
        if (users != null)
            return users.size();
        else
            return 0;
    }

    private class CardViewHolder extends RecyclerView.ViewHolder {
        private CircleSmartImageView imageView;
        private TextView userName;

        public CardViewHolder(View itemView) {
            super(itemView);
            imageView = (CircleSmartImageView) itemView.findViewById(R.id.join_user_icon);
            userName = (TextView) itemView.findViewById(R.id.join_user_name);
        }
    }
}
